#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START openssh
# depends: openssl1.1
# depends: zlib

reset_mtime openssh openssh/configure
rm -rf build/openssh
mkdir -p build/openssh
cd build/openssh
env \
	ac_cv_path_LOGIN_PROGRAM_FALLBACK=$prefix/bin/login \
	ac_cv_path_NROFF=$prefix/bin/nroff \
	ac_cv_path_PATH_PASSWD_PROG=$prefix/bin/passwd \
	ac_cv_path_PROG_LASTLOG=$prefix/bin/lastlog \
	ac_cv_path_xauth_path=$prefix/bin/xauth \
../../openssh/configure \
	${CONFIGURE_ARGS} \
	--sysconfdir=/etc/ssh \
	--disable-strip \
	--without-rpath \
	--without-selinux \
	--without-audit \
	--without-pam \
	--with-openssl \
	--with-privsep-user=sshd \
	--with-privsep-path=/var/empty \
	--with-default-path=$prefix/bin:$prefix/sbin \
	--with-superuser-path=$prefix/bin:$prefix/sbin \
	${AUTOCRAP_KLUDGE}

cd ../..
make_build build/openssh
systemd_service_dir="${prefix}/lib/systemd/system"
mkdir -p -m 755 "${stage}${systemd_service_dir}"
mkdir -p -m 755 "${stage}${systemd_service_dir}/multi-user.target.wants"
cat > "${stage}${systemd_service_dir}/ssh.service" << EOF
[Unit]
Description=OpenSSH service
After=syslog.target network.target

[Service]
ExecStartPre=/usr/bin/ssh-keygen -A
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target
EOF
ln -s --target-directory="${stage}${systemd_service_dir}/multi-user.target.wants" ../ssh.service


# RECIPE END openssh
